import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @Auther: MFM
 * @Date: 2021/10/24 - 10 - 24 - 20:50
 * @version: 1.0
 */

public class Test1 {
    public static void main(String[] args) {
        Connection conn = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            // url = "jdbc:mysql://127.0.1:端口号/数据库名?数据库文字格式&&&时区=Asia/Shanghai&"
            String url = "jdbc:mysql://127.0.0.1:3306/test?characterEncoding=UTF-8&useSSL=false&useUnicode=true&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
            conn = DriverManager.getConnection(url, "root", "52zjx1314");
            //在jdbc中开启事务处理
            conn.setAutoCommit(false);

            conn.commit();
            ;
            conn.close();
        } catch (Exception ex) {
            try {
                conn.rollback();
            } catch (Exception ex1) {
                ex.printStackTrace();
            }
        }finally {
            try{
                conn.close();
            }catch (Exception ex){
                ex.printStackTrace();
            }
        }
    }
}
